package cn.stylefeng.guns.modular.tool.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.tool.entity.ToolRepairGoods;
import cn.stylefeng.guns.modular.tool.mapper.ToolRepairGoodsMapper;
import cn.stylefeng.guns.modular.tool.model.params.ToolRepairGoodsParam;
import cn.stylefeng.guns.modular.tool.model.result.ToolRepairGoodsResult;
import  cn.stylefeng.guns.modular.tool.service.ToolRepairGoodsService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 云仓移库表 服务实现类
 * </p>
 * @author zhucx
 * @since 2023-04-10
 */
@Service
public class ToolRepairGoodsServiceImpl extends ServiceImpl<ToolRepairGoodsMapper, ToolRepairGoods> implements ToolRepairGoodsService {

    @Override
    public void add(ToolRepairGoodsParam param){
        ToolRepairGoods entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(ToolRepairGoodsParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(ToolRepairGoodsParam param){
        ToolRepairGoods oldEntity = getOldEntity(param);
        ToolRepairGoods newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public ToolRepairGoodsResult findBySpec(ToolRepairGoodsParam param){
        return null;
    }

    @Override
    public List<ToolRepairGoodsResult> findListBySpec(ToolRepairGoodsParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(ToolRepairGoodsParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition,operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(ToolRepairGoodsParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private ToolRepairGoods getOldEntity(ToolRepairGoodsParam param) {
        return this.getById(getKey(param));
    }

    private ToolRepairGoods getEntity(ToolRepairGoodsParam param) {
        ToolRepairGoods entity = new ToolRepairGoods();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public boolean batchAddList(List<ToolRepairGoodsParam> list) {
		return this.baseMapper.batchAddList(list);
	}

}
